<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : remind.class.php   FILE_PATH : \\classes\application\remind.class.php
 * 网站提醒设置 操作类
 *
 * @copyright workflow_system 
 * @author 
 * @package 
 * @subpackage 
 * @version Thu Nov 29 16:19:42 CST 2007
 */

class RemindClass extends FrameWork {
	/**
	 * 邮件发送对象
	 *
	 * @var obj
	 */
	var $obj_send_site_mail;
	/**
	 * 短信发送对象
	 *
	 * @var obj
	 */
	var $obj_message;
	
	/**
	 * 添加设置信息
	 * @author workflow Develop Team
	 * @param  $input_param 设置信息
	 * @return bool
	 */
	function addRemind($input_param){
		//在基本会员表中添加会员记录
		$insert_rs = $GLOBALS['db']->InsertRow($input_param, 'remind', 'remind_id');
		return $insert_rs;		
	}
	
	/**
	 * 判断提醒信息是否存在
	 * @author workflow Develop Team
	 * @param  $condition 查找条件
	 * @param  $backtype 返回类型 1,bool 2,id 3，array
	 * @return bool
	 */
	function checkRemindExist($condition = "",$backtype = "1"){
		//得到条件语句
		$condition_str = $this->getCondition($condition);
		$check_array = $GLOBALS['db']->GetTheRow($condition_str,'remind','*');
		if (count($check_array) <= 0){
			return false;
		}else{
			if ($backtype == "1"){
				return true;
			}else if ($backtype == "2"){
				return $check_array['remind_id'];
			}else if ($backtype == "3"){
				return $check_array;
			}
		}
	}
	
	/**
	 * 更新网站提醒设置
	 * @author workflow Develop Team
	 * @param  
	 * @return int/bool/object/array
	 */
	function modifyRemind($input_param,$modify_id){
		$update_rs = $GLOBALS['db']->UpdateRow($modify_id,$input_param,"remind","remind_id");
		return $update_rs;
	}
	
	/**
	 * 构造查找条件
	 * @author workflow Develop Team
	 * @param  $condition 查找条件
	 * @return string
	 */
	function getCondition($condition){
		if ($condition['id'] != ""){
			$subsql .= " and remind.member_id = '" . $condition['id'] . "'";
		}
		if ($condition['name'] != ""){
			$subsql .= " and remind.login_name = '" . $condition['name'] . "'";
		}
		return $subsql;
	}
	
	/**
	 * 返回默认设置数组
	 * @author workflow Develop Team
	 * @param  $type 返回类型 1 check为数组形式，2 check为字符串形式（用于默认设置），
	 * @return array
	 */
	function defaultRemindArray($type){
		$array = array();
		$remind_array = CommonFrameWork::memberRemindMenu('return');
		if (is_array($remind_array)){
			foreach ($remind_array as $k => $v){
				if (is_array($v['body'])){
					foreach ($v['body'] as $k2 => $v2){
						if (is_array($v2['body'])){
							foreach ($v2['body'] as $k3 => $v3){
								if ($type == '1'){
									$remind_array[$k]['body'][$k2]['body'][$k3][$v3['tag']] = array('mail_check'=>$v3['mail_check'],'msg_check'=>$v3['msg_check']);
								}elseif ($type == '2'){
									$array[$v3['tag']] = $v3['mail_check'].'|'.$v3['msg_check'];
								}
							}
						}
					}
				}
			}
		}
		if ($type == '1'){
			return $remind_array;
		}elseif ($type == '2'){
			return $array;
		}	
	}
	
	/**
	 * 发送邮件 或者 发送短信
	 * @author workflow Develop Team
	 * @param  $remind_tag 操作的提醒标签
	 * @param  $module_name 内容模板 标识 $value_array 需要转换的变量及值，表现形式为一维数组，键为要替换的变量，值为替换的值
	 * @param  $member 会员名 $genre 发送类型 mail 邮件 msg 短信
	 * @return bool
	 */
	function setMessageOrMail($remind_tag,$module_name,$value_array,$member,$config=''){
		//判断会员是否设置了该操作的提醒
		$condition_member['name'] = $member;
		$remind_array = $this->checkRemindExist($condition_member,'3');
		if (false == $remind_array){
			return false;
		}else {
			$line = @explode('|',$remind_array[$remind_tag]);
		}

		/**
		 * 创建邮件发送对象
		 */
		if (!is_object($this->obj_send_site_mail)){
			require_once("sendsitemail.class.php");
			$this->obj_send_site_mail = new SendSiteMail();
		}
		//发送邮件
		if ($line[0] == "1"){
			/**
			 * 创建会员操作
			 */
			if (!is_object($obj_member)){
				require_once("member.class.php");
				$obj_member = new MemberClass();
			}
			//取会员资料
			$condition['member_name'] = $member;
			$member_array = $obj_member->getMemberInfo($condition);
			//取后台设定的模板内容
			$this->obj_send_site_mail->smtpconfig = $config;
			$this->obj_send_site_mail->SendMail($module_name,$value_array,$member_array['email']);
		}
		//发送短信
		if ($line[1] == "1"){
			//取后台设定的模板内容
			$content = $this->obj_send_site_mail->SendMail($module_name,$value_array,$sendmail,true);
			//新增一条站内短消息
			$value_array = array();
			$value_array['member_name'] = 0;//系统发送
			$value_array['txtReceive_name'] = $member;//接收人用户名
			$value_array['txtTitle'] = $content['title'];//标题
			$value_array['txtContent'] = $content['content'];//内容
			if (!is_object($this->obj_message)){
				require_once("message.class.php");
				$this->obj_message = new MessageClass();
			}
			$this->obj_message->addMessage($value_array);
		}
		return true;		
	}

}

?>